home comics writing pictures archive about

HexDump.asm

Language: 8080 Assembly
Last Modified: 2022-11-12 4:27:45 PM UTC
File Size: 8973 bytes
http://www.penguinstew.ca/example/AltairHexDump/HexDump.asm
; HexDump program, prompts for Start Address and End Address then outputs
; the memory between those two addresses in intel HEX format
ORG 173000Q
LXI SP, 173000Q ; 173000: 061 000 366 Init stack pointer
MVI A, 003Q ; 173003: 076 003 Clear/Init 2SIO port
OUT 020Q ; 173005: 323 020
MVI A, 025Q ; 173007: 076 025
OUT 020Q ; 173011: 323 020
LXI H, StartPmt ; 173013: 041 015 367 Display Start Prompt
CALL PrintStrZ ; 173016: 315 173 366
CALL ReadHex16 ; 173021: 315 222 366 Read Start Address
LXI H, EndPmt ; 173024: 041 035 367 Display End Prompt
CALL PrintStrZ ; 173027: 315 173 366
XCHG ; 173032: 353
CALL ReadHex16 ; 173033: 315 222 366 Read End Address
INX D ; 173036: 023 Increment to make inclusive
MAINLOOP: MOV A, E ; 173037: 173 Calculate remaning length
SUB L ; 173040: 225
MOV C, A ; 173041: 117
MOV A, D ; 173042: 172
SBB H ; 173043: 234
JNZ SET16 ; 173044: 302 065 366 Set length to 16 if greater than 255
MOV A, C ; 173047: 171
CPI 020Q ; 173050: 376 020 Set length to 16 if greater than 16
JNC SET16 ; 173052: 322 065 366
CPI 000Q ; 173055: 376 000
JZ FINISH ; 173057: 312 155 366 Fininish dump if length is 0
JMP START ; 173062: 303 067 366
SET16: MVI C, 020Q ; 173065: 016 020
START: PUSH D ; 173067: 325 Store end address
XCHG ; 173070: 353 Store current address
LXI H, NewLine ; 173071: 041 055 367 Print record begining
CALL PrintStrZ ; 173074: 315 173 366
XCHG ; 173077: 353 Restore current address
MOV E, C ; 173100: 131 Store length
MOV A, E ; 173101: 173 Print length byte
CALL PrintHex8 ; 173102: 315 337 366
ADD H ; 173105: 204 Checksum accumulation
MOV D, A ; 173106: 127
MOV A, H ; 173107: 174 Print high address byte
CALL PrintHex8 ; 173110: 315 337 366
MOV A, L ; 173113: 175 Print low address byte
CALL PrintHex8 ; 173114: 315 337 366
ADD D ; 173117: 202 Checksum accumulation
MOV D, A ; 173120: 127
MVI A, '0' ; 173121: 076 060 Print Data Record Type
CALL PrintChar ; 173123: 315 206 366
CALL PrintChar ; 173126: 315 206 366
DATALOOP: MOV A, M ; 173131: 176 Load memory byte
CALL PrintHex8 ; 173132: 315 337 366 Print memory byte
ADD D ; 173135: 202 Checksum accumulation
MOV A, D ; 173136: 127
INX H ; 173137: 043 Move to next byte
DCR E ; 173140: 035 Decrement length
JNZ DATALOOP ; 173141: 302 131 366 Loop if bytes remain
CMA ; 173144: 057 Print checksum as 2's complement
INR A ; 173145: 074
CALL PrintHex8 ; 173146: 315 337 366
POP D ; 173151: 321 Restore end address
JMP MAINLOOP ; 173152: 303 037 366
FINISH: LXI H, EOFLine ; 173155: 041 377 366 Print end-of-file record
CALL PrintStrZ ; 173160: 315 173 366
CHK: IN 020Q ; 173163: 333 020 Ensure buffer is empty
ANI 002Q ; 173165: 346 002
JZ CHK ; 173167: 312 163 366
HLT ; 173172: 166 Complete
; Prints a Null terminated string from HL
PrintStrZ: MOV A, M ; 173173: 176
CPI 000Q ; 173174: 376 000
RZ ; 173176: 310
CALL PrintChar ; 173177: 315 206 366
INX H ; 173202: 043
JMP PrintStrZ ; 173203: 303 173 366
; Prints a character in A, uses B as temp storage
PrintChar: MOV B, A ; 173206: 107
CHECK: IN 020Q ; 173207: 333 020
ANI 002Q ; 173211: 346 002
JZ CHECK ; 173213: 312 207 366
MOV A, B ; 173216: 170
OUT 021Q ; 173217: 323 021
RET ; 173221: 311
; Read two bytes, high byte is in D and low byte is in E
ReadHex16: CALL ReadHex8 ; 173222: 315 232 366 Read High order byte
MOV D, E ; 173225: 123 Store Value
CALL ReadHex8 ; 173226: 315 232 366 Read Low order byte
RET ; 173231: 311
; Read a byte and puts it in E
ReadHex8: CALL ReadHex4 ; 173232: 315 250 366
RLC ; 173235: 007
RLC ; 173236: 007
RLC ; 173237: 007
RLC ; 173240: 007
MOV E, A ; 173241: 007
CALL ReadHex4 ; 173242: 315 250 366
ADD E ; 173245: 203
MOV E, A ; 173246: 137
RET ; 173247: 311
; Reads a nibble and puts it in A, uses C as temp storage
ReadHex4: IN 020Q ; 173250: 333 020
RRC ; 173252: 017
JNC ReadHex4 ; 173253: 322 250 366
IN 021Q ; 173256: 333 021
CPI '0' ; 173260: 376 060
JC ReadHex4 ; 173262: 332 250 366
CPI ':' ; 173265: 376 072
JC NUM ; 173267: 332 323 366
CPI 'A' ; 173272: 376 101
JC ReadHex4 ; 173274: 332 250 366
CPI 'G' ; 173277: 376 107
JC UPPER ; 173301: 332 330 366
CPI 'a' ; 173304: 376 141
JC ReadHex4 ; 173306: 332 250 366
CPI 'g' ; 173311: 376 147
JNC ReadHex4 ; 173313: 322 250 366
MVI C, 127Q ; 173316: 016 127
JMP PRINT ; 173320: 303 332 366
NUM: MVI C, '0' ; 173323: 016 060
JMP PRINT ; 173325: 303 332 366
UPPER: MVI C, 067Q ; 173330: 016 067
PRINT: CALL PrintChar ; 173332: 315 306 366
SUB C ; 173335: 221
RET ; 173336: 311
; Prints the byte in A using hex digits, uses C as temp storage
PrintHex8: MOV C, A ; 173337: 117 Store value
RRC ; 173340: 017 Rotate high nibble to low nibble
RRC ; 173341: 017
RRC ; 173342: 017
RRC ; 173343: 017
CALL PrintHex4 ; 173344: 315 355 366 Print high nibble
MOV A, C ; 173347: 171 Restore value
CALL PrintHex4 ; 173350: 315 355 366 Print low nibble
MOV A, C ; 173353: 171 Restore value
RET ; 173354: 311
; Prints the nibble in A using hex digits
PrintHex4: ANI A, 017Q ;173355: 346 017 Clear high nibble
CPI 012Q ;173357: 376 012 If greater than 10
JNC LETTER ;173361: 322 371 366 It's a letter digit, else it's a number digit
ADI '0' ;173364: 306 060 Determine offset from '0' character
JMP OUTPUT ;173366: 303 373 366
LETTER: ADI 067Q ;173371: 306 067 Determine offset from 'A' character
OUTPUT: CALL PrintChar ;173373: 315 206 366
RET ;173376: 311
EOFLine: "\r\n:00000001FF" ; 173377: 015 012 072 060 060 060 060 060 060 060 061 106 106 000
StartPmt: "Start Address: " ; 173415: 123 164 141 162 164 040 101 144 144 162 145 163 163 072 040 000
EndPmt: "\r\nEnd Address: " ; 173435: 015 012 105 156 144 040 101 144 144 162 145 163 163 072 040 000
NewLine: "\r\n:" ; 173455: 015 012 072 000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148